home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
tcpech1a
/
modmain.bas
< prev
next >
Wrap
BASIC Source File
|
1999-08-31
|
4KB
|
146 lines
Attribute VB_Name = "modMain"
Option Explicit
'Constants
Const MyModule = "modMain"
'Variables
Public Timings As Boolean
Public QuitGame As Boolean
'Classes - for every one you add, release in shutdown routine.
Public Perf As clsPerformanceMonitor
Public CScreen As clsScreen
Public G As clsGlobal
'Declares
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)
'Enums
Public Enum enumLights
ltDisconnected = vbBlack
ltIdle = vbGreen
ltTCPUnspecifiedWriteError = &HFFFF00
ltTCPReadError = &H80FF
ltTCPSendError = vbRed
ltTCPSendTextError = vbYellow
ltTCPBlocked = vbBlue
End Enum
Public Sub Main()
'------------------------------------------------------------
'Main startup routine
'------------------------------------------------------------
Const MyError = MyModule & "_" & "Main"
On Error GoTo Err_Init
'Turn off timings
Timings = False
QuitGame = False
'Initialize performance monitor class
Set Perf = New clsPerformanceMonitor
'Initialize the 'global variable' class
Set G = New clsGlobal
'Initialize the screen handler class
Set CScreen = New clsScreen
CScreen.Init
'Initialize the TCP class
TCP.Init
'Set the current time/date
G.StartTime = Now
G.CurrentTime = Now
Exit Sub
Err_Init:
CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
Resume Next
End Sub
Public Sub GameShutDown()
'------------------------------------------------------------
'Shutdown routine
'------------------------------------------------------------
'Turn off timings
Timings = False
'Release all sockets
TCP.TCPShutDown
'Release all classes
Set Perf = Nothing
Set CScreen = Nothing
Set G = Nothing
End Sub
Public Sub PerformanceStartTime(ByVal RoutineName As String)
'------------------------------------------------------------
'Performance monitor start routine - call at beginning of procedure
'------------------------------------------------------------
Const MyError = MyModule & "_" & "PerformanceStartTime"
On Error GoTo Err_Init
If Perf(RoutineName).PerfStartTime = 0 Then
'dummy check to kick off an error if it doesn't exist.
End If
With Perf(RoutineName)
.PerfStartTime = timeGetTime
.PerfHitCount = .PerfHitCount + 1
End With
Exit Sub
Err_Init:
If Err.Number = 5 Then
'item already exists
Perf.Add RoutineName, 0, 0, 0, RoutineName
Resume Next
Else
CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
Resume Next
End If
End Sub
Public Sub PerformanceEndTime(ByVal RoutineName As String)
'------------------------------------------------------------
'Performance monitor end routine - call at end of procedure
'------------------------------------------------------------
Const MyError = MyModule & "_" & "PerformanceEndTime"
On Error GoTo Err_Init
If Perf(RoutineName).PerfStartTime = 0 Then
'dummy check to kick off an error if it doesn't exist.
End If
With Perf(RoutineName)
.PerfEndTime = timeGetTime
.PerfTotalTime = .PerfTotalTime + (.PerfEndTime - .PerfStartTime)
End With
Exit Sub
Err_Init:
CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
Resume Next
End Sub
Public Function Random(lowerBound As Long, upperBound As Long)
Const MyError = MyModule & "_" & "Random"
If Timings Then PerformanceStartTime MyError
Random = (Int((upperBound - lowerBound + 1) * Rnd + lowerBound))
If Timings Then PerformanceEndTime MyError
End Function